<template>
	<view>
		<!--pages/paySuccess/paySuccess.wxml-->
		<view class="payment-img">
			<image src="https://safood.supplyocta.com/Public/MallSmallApp/pay_success.png"></image>
		</view>
		<view class="payment-txt">支付成功</view>
		<view class="payment-money">￥{{money}}</view>
		<view v-if="pick_code" class="payment-code">
			<text>提货码</text>
			<text>{{pick_code}}</text>
		</view>
		<view class="payment-group">
			<view class="back-index" @tap="backIndex">返回首页</view>
			<view class="see-order" @tap="seeOrder">查看订单</view>
		</view>

		<!-- 红包 -->
		<view class="container" v-if="reward">
			<view class="box">
				<image src="https://safood.supplyocta.com/Public/MallSmallApp/reward-bg.png" class="reward-bg"></image>
				<view @tap="toOpen" :class="'reward-open ' + (rotate?'reward-rotate':'')">
					<image v-if="rotate" src="https://safood.supplyocta.com/Public/MallSmallApp/open-1.png"></image>
					<image v-else src="https://www.xzthealth.com/Public/MallSmallApp/open.png"></image>
				</view>
				<view class="reward-money" v-if="open">
					<text>￥</text>
					<text>{{reward_money}}</text>
				</view>
				<view class="reward-tip" v-if="!open">恭喜发财，大吉大利！</view>
				<view class="reward-tip" v-else>已放入会员卡余额</view>
				<view @tap="closeReward" class="reward-close">
					<icon type="cancel" size="30" color="#ffffff"></icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// pages/paySuccess/paySuccess.js
	var app = getApp().globalData;

	export default {
		data() {
			return {
				money: 0,
				order_no: '',
				pick_code: '',
				open: false,
				rotate: false,
				reward: false,
				reward_money: 0,
				activity_type: 0,
				//1转盘活动  2红包活动
				activity_id: 0,
				order_id: "",
				order_genre: "",
				image_header: ''
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		async onLoad(options) {
			await this.$onLaunched;
			
			this.image_header = this.$store.image_header
			
			this.setData({
				money: options.money,
				order_no: options.order_no,
				order_id: options.order_id,
				pick_code: options.pick_code ? options.pick_code : '',
				order_genre: options.order_genre
			});

			if (options.order_genre == 1) {
				var that = this;
				var user = uni.getStorageSync('userInfo'); //获取红包

				getApp().globalData.sendRequest({
					url: "/Reward/getPayReward",
					data: {
						order_no: options.order_no,
						vid: user.vid ? user.vid : 0
					},
					showLoading: false,
					success: function(res) {
						if (res.status == 1) {
							that.setData({
								reward: true
							});
						}
					}
				});
			}
		},
		methods: {
			//查看订单
			seeOrder: function() {
				switch (this.order_genre) {
					case '1':
					case '3':
					case '4':
						//1普通 2秒杀 3预售
						uni.redirectTo({
							url: '/pages/order/myOrderDetail/myOrderDetail?order_no=' + this.order_no
						});
						break;

					case '2':
						//拼团订单
						uni.redirectTo({
							url: '../../index/Collage/Collage?order_id=' + this.order_id + '&ty=1&type=1'
						});
						break;
				}
			},
			//返回首页
			backIndex() {
				this.$store.merHomeState ? uni.reLaunch({
					url: '/pages/mer/tabbar/home/home'
				}) : uni.reLaunch({
					url: '/pages/store/store'
				});
			},
			notify: function() {
				if (this.activity_type == 1) {
					//大转盘
					var that = this;
					uni.showModal({
						cancelText: '狠心放弃',
						cancelColor: '#999999',
						confirmColor: '#ff5c6d',
						confirmText: '去抽奖',
						content: '恭喜你获得一次大转盘的机会',
						showCancel: true,
						title: '获得大转盘机会',
						success: result => {
							if (result.confirm) {
								uni.navigateTo({
									url: '/pages/index/TurnTable/TurnTable?turntable_id=' + that.turntable_id + "order_no=" + that.order_no
								});
							}
						}
					});
				}
			},
			//拆红包
			toOpen: function() {
				if (!this.rotate) {
					// if (this.data.isVip != 1) {
					//     uni.showModal({
					//         title: '温馨提示',
					//         content: '您没有激活会员卡，去激活会员领取红包吧！',
					//         showCancel: true,
					//         cancelText: '狠心放弃',
					//         confirmColor: '#ff5c6d',
					//         confirmText: '去激活',
					//         success: function (res) {
					//             if (res.confirm) {
					//                 uni.navigateTo({
					//                     url: '../card/card'
					//                 })
					//             }
					//         }
					//     })
					//     return;
					// }
					this.setData({
						rotate: true
					});
					var that = this;
					getApp().globalData.sendRequest({
						url: '/Reward/openPayReward',
						type: "post",
						data: {
							order_no: that.order_no
						},
						showLoading: false,
						success: function(res) {
							// console.log(res);
							if (res.status == 1) {
								that.setData({
									reward_money: res.money,
									open: true
								});
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 1500
								});
								that.closeReward();
							}
						}
					});
				}
			},
			//关闭拆红包
			closeReward: function() {
				this.setData({
					reward: false
				});
			}
		}
	};
</script>
<style>
	@import "./paySuccess.css";
</style>
